package com.hup.utils.swing;

import com.hup.utils.commons.start.BaseAppTray;
import com.hup.utils.commons.start.BaseAppTray.SimpleMenu;
import com.hup.utils.commons.start.BaseAppTray.TrayActionListener;
import com.hup.utils.commons.start.StartupInfo;
import com.hup.utils.commons.swing.SimpleTestFrame;
import lombok.extern.log4j.Log4j2;

import javax.swing.*;

/**
 * 用于辅助托盘图标设计
 * @author hugan
 * @date 2020/4/8
 */
@Log4j2
public class TrayIconTool {

    private static JFrame frame;
    public static void main(String[] args) {
        SimpleTestFrame.show(param -> frame = param);
        BaseAppTray tray = new BaseAppTray("/static/icon/icon_add.gif", StartupInfo.getApplicationName());
        SimpleMenu simpleMenu = tray.createMenu().addExit();
        tray.setPopupMenu(simpleMenu, null);
        tray.setTrayListener(new TrayActionListener() {
            @Override
            public void onClickTray() {
                String icon = "G:/proPS/proImages/app_tray.gif";
                tray.setImage(IconUtil.getFileImageNoCache(icon, "外部图标"));
                //tray.setImage(AppIcon.getIcon("xx", "外部图标").getImage());
                log.info("已刷新图标");
            }

            @Override
            public void onExit(BaseAppTray appTray) {
                appTray.doHide();
                System.exit(0);
            }
        });
        tray.doShow();
        frame.dispose();
    }

}
